﻿using Core.Dtos;
using Core.Domain;
using Core.IRepository;
using Core.IServices;
using Core.Queries;
using Library.Cache;
using Library.Helpers;
using Library.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Core.Mappers;
using Core.Aspects;
using Core.Messages;
using Core.IRepository.Admin;

namespace Services
{
    [CacheName("Culture")]
    public class ManageCultureService : BaseService, IManageCultureService
    {
        private const string CULTURE_SETTINGS = "Cultures";

        private readonly IAdminRepository<byte, Culture> repository;
        private readonly IAdminUnitOfWork unitOfWork;
        private readonly IGenericReaderService<byte, Culture, CultureDto, CultureQuery> readerService;
        private readonly IGenericWriterService<byte, Culture, CultureDto, CultureQuery> writerService;

        public ManageCultureService(IAdminUnitOfWork unitOfWork, IAdminRepository<byte, Culture> repository, IGenericReaderService<byte, Culture, CultureDto, CultureQuery> readerService, IGenericWriterService<byte, Culture, CultureDto, CultureQuery> writerService)
        {
            this.repository = repository;
            this.unitOfWork = unitOfWork;
            this.readerService = readerService;
            this.writerService = writerService;
            readerService.Initialize(unitOfWork, repository);
            writerService.Initialize(unitOfWork, repository);
        }

        [Cache]
        public CultureDto FindByID(byte id)
        {
            return readerService.FindByID(id);
        }

        public QueryResponse<CultureDto> FindBy(Request<CultureQuery> request)
        {
            return readerService.FindBy(request);
        }

        public Response<byte> Add(Request<CultureDto> dto)
        {
            return writerService.Add(dto);
        }

        [DeleteCache]
        public Response Edit(byte id, Request<CultureDto> dto)
        {
            return writerService.Edit(id, dto);
        }

        [DeleteCache]
        public Response Delete(byte id)
        {
            return writerService.Delete(id);
        }
    }
}